﻿using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace RemoteServer
{
    class MyServer
    {
        //使用 STAThread 标记 Windows 窗体的入口点
        [STAThread]
        static void Main(string[] args)
        {
            ////注册通道
            //TcpChannel channel = new TcpChannel(8899);
            //ChannelServices.RegisterChannel(channel);
            ////注册远程对象
            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject.RemotingObject),
            //                                                   "RemoteObject.RemoteObject",
            //                                                   WellKnownObjectMode.SingleCall);
            //Console.ReadLine();
            RemotingConfiguration.Configure("RemoteServer.exe.config");//remoting配置是分辨大小写的
            //查找问题请一步一步走，最终找到错误处，
            //请求不到服务，检查服务端的channel、service中的配置跟客户端请求的url是否一致，如端口等
            //查找上面没问题，那从服务端开始：1、先查找注册的端口是否存在了（ChannelServices.RegisteredChannels.Length）
            //2、查找注册的远程对象是否存在(RemotingConfiguration.GetRegisteredWellKnownServiceTypes().Length)
            //如果服务端没问题再查客户端
            //TcpChannel channel = new TcpChannel(8899);
            //ChannelServices.RegisterChannel(channel);
            ////注册远程对象
            //RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject.RemoteOpration),
                                                              // "RemoteObject.RemoteOpration",
                                                              // WellKnownObjectMode.SingleCall);
            Console.Write(RemotingConfiguration.GetRegisteredWellKnownServiceTypes().Length);
            
            Console.ReadLine();
        }
    }
}
